<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
    
<%@ include file="global.jsp" %>
    
<%
	boolean errorInEditPassword = false;
	boolean errorNoPassword = false;
	boolean errorNoConfirmPassword = false;
	boolean errorPasswordsNotEqual = false;
	
	boolean bUpdateSuccess = false;
	
	boolean doCreate  = ParamUtils.getBooleanParameter(request,"doCreate");
	if(doCreate)
	{
		String password         = ParamUtils.getParameter(request,"password");
		String confirmPassword  = ParamUtils.getParameter(request,"confirmPassword");
		
		if( password != null ) {
			password = password.trim();
			if( password.equals("") ) { password = null; }
		}
		if( confirmPassword != null ) {
			confirmPassword = confirmPassword.trim();
			if( confirmPassword.equals("") ) { confirmPassword = null; }
		}
		
		if( password == null ) {
			errorNoPassword = true;
		}
		if( confirmPassword == null ) {
			errorNoConfirmPassword = true;
		}
		if( password != null && confirmPassword != null
		    && !password.equals(confirmPassword) )
		{
			errorPasswordsNotEqual = true;
		}
		
		errorInEditPassword = errorNoPassword || errorNoConfirmPassword || errorPasswordsNotEqual ;
		if(errorInEditPassword == false)
		{
			UserManager usM = new UserManager();
			User usAdmin = usM.getUser("admin");
			if(usAdmin != null)
			{
				usAdmin.setMiMa(password);
				boolean bsuess = usAdmin.updateTODB();
				if(bsuess = false)
				{
					errorInEditPassword = true;
				}
				else
				{
					bUpdateSuccess = true;
				}
			}
			else
			{
				errorInEditPassword = true;
			}
		}
	}
	
	if(bUpdateSuccess == true)
	{
		response.sendRedirect("main.jsp");
		return;
	}
%>
 
<%@ include file="header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<p>

<%
    String title = "修改密码";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {title, "createUser.jsp"}
    };
    StringBuffer pageGuide = new StringBuffer();
    for (int i=0; i<breadcrumbs.length; i++){
      for(int j=0; j<breadcrumbs[i].length; j++){
          pageGuide.append(breadcrumbs[i][j]+"@");
      }
    }

%>

<jsp:include page="title.jsp" flush="true">
   <jsp:param name="title" value="<%=title%>" />
   <jsp:param name="pageGuide" value="<%=pageGuide%>" />
</jsp:include>

<font size="-1">
	<%
		if(errorInEditPassword)
		{
	%>
		<span id="errorInfo" style="color:Red;">修改不成功: 请检查密码是否为空,或者不一致...</span>
	
	<% } %>
</font>

<form action="adminSetting.jsp" method="post" name="editPasswordForm">
<input type="hidden" name="doCreate" value="true">
<table  cellspacing="0" cellpadding="0" border="0" width="95%" align="right">
<td>
<table width="100%" height="81" border="0" cellpadding="3" cellspacing="1">

<%-- password --%>
<tr bgcolor="#ffffff">
	<td><font size="-1"> 
		 口令 :</font></td>
	<td><input type="password" name="password" value="" size="20" maxlength="30"></td>
</tr>

<%-- confirm password --%>
<tr bgcolor="#ffffff">
	<td><font size="-1">
		 请再次输入口令 :</font></td>
	<td><input type="password" name="confirmPassword" value="" size="20" maxlength="30"></td>
</tr>
<tr>
	<td> &nbsp; </td>
	<td> &nbsp; </td>
</tr>

<tr >
	<td align="right">
	<input type="submit" value="修改密码" />
	</td>
	<td>
	<input type="submit" value="放 弃"
 		onclick="location.href='main.jsp';return false;" />
	</td>
</tr>

</table>
</td>
</table>
</form>

<%@ include file="footer.jsp" %>